#include <kwdb/client.h>
#include <iostream>

int main() {
    // Test with wrong port - should fail immediately
    kwdb::IngestConfig config;
    config.ingest_endpoint = "127.0.0.1:9999"; // Wrong port
    config.timeout_ms = 5000;

    kwdb::KwdbClient client(config);

    kwdb::Point point("test_measurement");
    point.add_tag("host", "test");
    point.add_field("value", 42.0);

    auto status = client.write(point);
    if (!status.ok()) {
        std::cout << "Expected failure with wrong endpoint: " << status.message << std::endl;

        // Now test with correct port
        kwdb::IngestConfig config2;
        config2.ingest_endpoint = "127.0.0.1:9090";
        config2.timeout_ms = 5000;

        kwdb::KwdbClient client2(config2);
        auto status2 = client2.write(point);

        if (status2.ok()) {
            std::cout << "Success with correct endpoint!" << std::endl;
            return 0;
        } else {
            std::cout << "Failed with correct endpoint: " << status2.message << std::endl;
            return 1;
        }
    } else {
        std::cout << "ERROR: Should have failed with wrong port!" << std::endl;
        return 1;
    }
}